#pragma once
#include "noncopyable.h"
#include<functional>
#include<string>
#include<memory>
#include<vector>

class EventLoop;
class EventLoopThread;
class EventLoopThreadPool :noncopyable
{
    public:
    using ThreadInitCallback  = std::function<void(EventLoop*)>;

    EventLoopThreadPool(EventLoop* baseLoop,const std::string& nameArg);

    ~EventLoopThreadPool();

    void setThreadNum(int numThreads){numThreads_ = numThreads;}

    void start(const ThreadInitCallback& cb);

    std::vector<EventLoop *> getAllLoops();
    // 如果是多线程，baseLoop_默认以轮询的方式分配Channel给subLoop
    EventLoop* getNextLoop();


    bool started() const {return started_;}

    const std::string& name() const{
        return name_;
    }
    private:
    EventLoop* baseLoop_; // EventLoop loop; 用户创建的一开始的Loop
    std::string name_;
    bool started_;
    int numThreads_;
    int next_;  // 用来轮询派发任务的
    std::vector<std::unique_ptr<EventLoopThread>> threads_; // 封装了批量的EventLoopThread
    std::vector<EventLoop*> loops_;
};